package com.channel.temperature.collect.ui.adapter

import android.util.Log
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.channel.temperature.collect.R
import com.channel.temperature.collect.app.util.MyUtil
import com.channel.temperature.collect.data.response.TaskBean
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Date


class TaskAdapter : BaseQuickAdapter<TaskBean, BaseViewHolder>(R.layout.item_task) {

    override fun convert(holder: BaseViewHolder, item: TaskBean) {
        if (!checkTime(item.taskTime)) {
            Log.e("convert", "convert   " + item.taskTime)
            holder.setText(R.id.descType, "压力" + (holder.adapterPosition + 1) + ":")
            holder.setText(
                R.id.time,
                "" + MyUtil.formatFloat(item.taskTime.toFloat(), 2, 0.00f) + "Mpa"
            )
            holder.setText(R.id.delayTime, "" + item.delayTime + "秒")
        } else {
            holder.setText(R.id.descType, "采集时间:")
            holder.setText(R.id.time, "" + MyUtil.DateToStr(MyUtil.StrToDate(item.taskTime)))
            holder.setText(R.id.delayTime, "" + item.delayTime + "秒")
        }

    }

    //是正确时间 那就是采集参数 否则就是压力参数
    fun checkTime(str: String): Boolean {
        var isTime = true
        val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        var date: Date? = null
        try {
            date = format.parse(str)
        } catch (e: ParseException) {
            e.printStackTrace()
            isTime = false
        }
        return isTime
    }

}